/**
 * @author        Nicolas Bottarini <nicolasbottarini@gmail.com>, 404 <http://www.proyecto404.com>
 * @version       $Rev: 3 $
 * @lastrevision  $Date: 2011-09-12 16:45:37 +0000 (Mon, 12 Sep 2011) $	 
 */
package com.proyecto404.core {
	import com.proyecto404.core.util.ClassHelper;

	/**
	 * @abstract
	 */
	public class BaseObject implements IBaseObject { 
		/**
		 * Test for equality.
		 * Method Should be overriden
		 */
		public function equals(value:*):Boolean {
			if (!(value is BaseObject)) {
				return false;
			}
			
			return value == this;
		}
		
		public static function areEquals(value1:*, value2:*):Boolean {
			if (value1 is BaseObject) {
				return BaseObject(value1).equals(value2);
			} else {
				return value1 == value2;
			}
		}
		
		public function toString():String {
			return getClassName();
		}
		
		public function getClass():Class {
			return ClassHelper.getClass(this);
		}
		
		public function getClassName():String {
			return ClassHelper.getClassName(this);
		}
		
		public function setProps(o:Object,props:Object):* {
			for (var n:String in props) {
				o[n] = props[n];
			}
			return o;
		}
		
		public static function valueToString(value:*):String {
			if (value is BaseObject) {
				return BaseObject(value).toString();
			} else if (value is Array) {
				var string:String = "Array{";
				var first:Boolean = true;
				for each(var item:* in value as Array) {
					if (!first) {
						string += ",";
					} else {
						first = false;
					}
					string += valueToString(item);
				}
				string += "}";
				return string;
			} else if (value is String) {
				return value;		
			} else {
				return value.toString();
			}
		}
	}
}